﻿using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CallCenter.Data;
using CallCenter.Data.BizUtilities;
using System.Configuration;
using System.Data;
using CallCenter.Security;
using CallCenter.Data.Models;
using CallCenter.Data.Misc;
namespace CallCenter.Web.Controllers
{
    public class CommunicationMessageGridController : BaseController
    {
        // GET: CommunicationMessageGrid
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CommunicationMsgHistory()
        {
            CommunicationMessageGridController cmpy = new CommunicationMessageGridController();
            return View(cmpy);
        }
        public JsonResult GetCommunicationMessages(int id)
        {
            var scratchPads = this.Bridge.CommunicationUtility.GetAllGrid(id, this.Bridge.AccountUtility.GetUserIDByUserNames(User.Identity.Name.ToLower()));
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetAllContacts()
        {
            var scratchPads = this.Bridge.CommunicationUtility.GetAllContactsForMsg();
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }
        //public JsonResult GetAllProducts()
        //{
        //    var scratchPads = this.Bridge.CommunicationUtility.GetA();
        //    return Json(scratchPads, JsonRequestBehavior.AllowGet);
        //}

        public JsonResult GetContactMSG(int id)
        {
            var scratchPads = this.Bridge.CommunicationUtility.GetContactMSG(id, 24);
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }


        [HttpPost]
        public JsonResult CreateCompanyMessages(CompanyCommunicationViewModel model)
        {
           
            int userId = this.Bridge.AccountUtility.GetUserIDByUserNames(User.Identity.Name.ToLower());
            model.userID = userId;

            var returnMessage = this.Bridge.CommunicationUtility.InsertToCompanyComm(model); ;
            if (!returnMessage.Status)
                ModelState.AddModelError("Error", returnMessage.Message);
            else {
                return Json(new AjaxSuccess { Message = "Success" }, JsonRequestBehavior.AllowGet);
            }
        

            return Json(new AjaxFailure { Errors = ModelState.SerializeErrors }, JsonRequestBehavior.DenyGet);
        }


        [HttpPost]
        public JsonResult UpdateCompanyMessages(CompanyCommunicationViewModel model)
        {
            int userId = this.Bridge.AccountUtility.GetUserIDByUserNames(User.Identity.Name.ToLower());
            model.userID = userId;
            var returnMessage = this.Bridge.CommunicationUtility.UpdateToCompanyComm(model); ;
            if (!returnMessage.Status)
                ModelState.AddModelError("Error", returnMessage.Message);
            else {
                return Json(new AjaxSuccess { Message = "Success" }, JsonRequestBehavior.AllowGet);
            }
            return Json(new AjaxFailure { Errors = ModelState.SerializeErrors }, JsonRequestBehavior.DenyGet);
        }


        [HttpPost]
        public JsonResult DeleteCompanyMessages(CompanyCommunicationViewModel model)
        {
          
            int id = model.id;
            this.Bridge.CommunicationUtility.Delete(id);
            var returnMessage = "Success";
            return Json(returnMessage, JsonRequestBehavior.AllowGet);

        }

       

        [HttpPost]
        public JsonResult GetAllCompanyContacts(int id)//CompanyContactsViewModel model, int id)
        {
          
            var scratchPads = this.Bridge.CompanyContactsUtility.GetAllCompany(id);
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }



    }
}